import 'package:dio/dio.dart';
import 'package:wuxu_flutter_lianxi/env/config.dart';

class LogsInterceptor extends InterceptorsWrapper {
  @override
  void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
    if (Config.debug) {
      print("请求头url:${options.path} ${options.method}");
      print('请求头: ${options.headers}');
      if (options.data != null) {
        print('请求参数: ${options.data}');
      }
    }

    super.onRequest(options, handler);
  }

  @override
  void onResponse(Response response, ResponseInterceptorHandler handler) {
    if (Config.debug) {
      print('返回参数: ${response.toString()}');
    }
    super.onResponse(response, handler);
  }

  @override
  void onError(DioException err, ErrorInterceptorHandler handler) {
    if (Config.debug) {
      print('栈:${err.stackTrace.toString()}');
      print('请求异常: ${err.toString()}');
      print('请求异常信息: ${err.response.toString()}');
    }
    super.onError(err, handler);
  }
}
